#pragma once

#include "ServerParticipant.h"
#include "Message.h"
#include "MessageBuilder.h"
#include <set>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/shared_ptr.hpp>
#include "GameStateAccessor.h"

class GalconRoom
{
public:

   GalconRoom(boost::asio::io_service& ioService);

   ~GalconRoom();

   void Join(ServerParticipantPtr participant);

   void Leave(ServerParticipantPtr participant);

   
   void Deliver(const Message& msg);


   void Deliver(const Message& msg, ServerParticipantPtr participant);

   GameStateAccessorPtr GetGameStateAccessor() const 
   {
      return m_gameStateAccessor; 
   }

private:
   void traceMessage(const Message&, const std::string&);
   void doUpdateGameState();
   void startGame();
   void sendRejectionMessage( ServerParticipantPtr, RejectionReason);
   void handle_timer(const boost::system::error_code& error);
   std::set<ServerParticipantPtr> m_participants;
   boost::shared_ptr<boost::asio::deadline_timer> m_timer;
   boost::asio::io_service& m_ioService;
   GameStateAccessorPtr m_gameStateAccessor;
   
};

typedef boost::shared_ptr<GalconRoom> GalconRoomPtr;